/* 
 * File:   APEPluginIO.cpp
 * Author: hao
 * 
 * Created on 2011年5月17日, 下午11:52
 */

#include "APEPluginIO.h"

APEPluginIO::APEPluginIO() : data(NULL), currentposition(0) {
}

int APEPluginIO::Read(void* pBuffer, unsigned int nBytesToRead, unsigned int* pBytesRead) {

    if (currentposition >= Length) return 0;

    if (currentposition + nBytesToRead >= Length) {
        *pBytesRead = Length - currentposition;
    } else {
        *pBytesRead = nBytesToRead;
    }

    memcpy(pBuffer, data + currentposition, *pBytesRead);
    currentposition += *pBytesRead;

    return 0;

}

int APEPluginIO::Seek(int nDistance, unsigned int nMoveMode) {

    switch (nMoveMode) {
        case FILE_BEGIN:

            currentposition = nDistance;

            break;
        case FILE_CURRENT:
            
            currentposition += nDistance;

            break;
        case FILE_END:
            
            currentposition = Length - nDistance;
            
            break;
    }

    if (currentposition >= Length)
        currentposition = Length;
    if (currentposition < 0 )
        currentposition = 0;

    return 0;

}

int APEPluginIO::SetEOF(){
    currentposition = Length;
    return 0;
}



APEPluginIO::~APEPluginIO() {
}

